@tool
extends Node
#class_name TagSystem

@export var global_tags:Array[String]
const TAG_TREE = preload("res://Config/TagTree.tres")

func _ready() -> void:
	global_tags = filter_tags(TAG_TREE.tree)


func filter_tags(tree:Dictionary) -> Array[String]:
	var list:Array[String]
	for tag in tree:
		var t = tag as String
		if t.contains("."):
			list.append(tag)
		list.append_array(filter_tags(tree[tag]))
	return list 

## 如果tags中的标签全部存在于to_match中,则返回true,否则返回false
static func all_tags_match(tags:Array[String],to_match:Array[String]) -> bool:
	for tag in tags:
		if not to_match.has(tag):
			return false
	return true

## 如果有任一tags中的标签存在于to_match中，则返回true，否则返回false
static func any_tags_match(tags:Array[String],to_match:Array[String]) -> bool:
	for tag in tags:
		if to_match.has(tag):
			return true
	return false
